package app.server.project.main.service.db.dao.statics;

import app.server.project.main.service.db.entity.statics.StaticsRegEntity;
import app.server.project.main.service.db.mapper.statics.StaticsRegMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

@Repository
public class StaticRegDao extends ServiceImpl<StaticsRegMapper, StaticsRegEntity> {

    public void updateNum(int RegId, int num) {
        this.update(Wrappers.lambdaUpdate(StaticsRegEntity.class)
                .set(StaticsRegEntity::getNum, num)
                .set(StaticsRegEntity::getCreateTime, LocalDateTime.now())
                .eq(StaticsRegEntity::getId, RegId));
    }

    public StaticsRegEntity getOneByDayId(LocalDateTime start, LocalDateTime end) {
        return this.getOne(Wrappers.lambdaQuery(StaticsRegEntity.class)
                .ge(StaticsRegEntity::getCreateTime, start)
                .le(StaticsRegEntity::getCreateTime, end));
    }
}
